﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Main.aspx.cs" Inherits="Mall.Main" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>主页</title>
    <style type="text/css">
         #MainForm 
        {
            width: 600px;
            margin: auto;
            border: 1px solid black;
            text-align: center;
            font-size: 20px;
        }
        #BtnAudit 
        {
            background-color: White;
        }
        a 
        {
            color: blue;
        }
    </style>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
</head>
<body style="text-align: center">
    <%
        if (Session["Username"] != null)
        {
     %>
    <h1 style="color: Red; margin-top: 50px">欢迎<%=Session["Username"] != null ? Session["Username"].ToString() : ""%>，进入XX商城</h1><br />
    <%
        }
        else
        {
     %>
     <h1 style="color: Red; margin-top: 50px">XX商城，欢迎你</h1><br />
     <%
        }
     %>
    <form id="MainForm" runat="server">
    <div style="margin-top: 10px; ">
        <asp:Label ID="Label1" runat="server" Text="Label" style="color: Red; font-size: 24px;">商&nbsp;品&nbsp;列&nbsp;表</asp:Label><br />
    </div>
    <div style="margin-top: 10px; text-align: center; ">
        <asp:Panel ID="GoodsListPanel" runat="server" align="center" style="font-size: 16px">
            <div style="">
            <asp:GridView ID="GoodsDateView" runat="server" AutoGenerateColumns="False" 
                    OnRowDeleting="GridView1_RowDeleting" >
                <Columns>
                    <asp:TemplateField HeaderText="序号">
                    <ItemTemplate>
                        <%#Container.DataItemIndex+1%>
                    </ItemTemplate>
                    <ItemStyle Width="45px" HorizontalAlign="Center" />
                        <HeaderStyle Width="45px" />
                    </asp:TemplateField>
                    <asp:BoundField DataField="ID" HeaderText="ID" Visible="false">
                        <ItemStyle Width="50px" HorizontalAlign="Center" />
                        <HeaderStyle Width="50px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="NAME" HeaderText="商品名称">
                        <ItemStyle Width="120px" HorizontalAlign="Center" />
                        <HeaderStyle Width="120px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="PRICE" HeaderText="价格">
                        <ItemStyle Width="70px" HorizontalAlign="Center" />
                        <HeaderStyle Width="70px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="LOOK_NUM" HeaderText="浏览次数">
                        <ItemStyle Width="50px" HorizontalAlign="Center" />
                        <HeaderStyle  Width="50px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="CREATE_TIME" HeaderText="发布时间">
                        <ItemStyle Width="120px" HorizontalAlign="Center" />
                        <HeaderStyle  Width="120px" />
                    </asp:BoundField>
                    <asp:TemplateField  HeaderText="查看操作" ShowHeader="True" HeaderStyle-Width="45px">
                        <ItemTemplate>
                            <input runat="server" id="SelectBtn" type="button" value="查看" style="background-color: White; border: none; 
                                font-size: 16px; color: Blue; text-decoration: underline;" 
                                onclick="selectBtnClick(this.id)" />
                            <span style="display: none"><%# Eval("ID") %></span>
                        </ItemTemplate>
                        <ItemStyle Width="45px" HorizontalAlign="Center" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="修改操作" ShowHeader="True" HeaderStyle-Width="45px">
                        <ItemTemplate>
                            <input runat="server" id="EditBtn" type="button" value="编辑" style="background-color: White; border: none; 
                                font-size: 16px; color: Blue; text-decoration: underline;" 
                                onclick="editBtnClick(this.id)" />
                            <span style="display: none"><%# Eval("ID") %></span>
                        </ItemTemplate>
                        <ItemStyle Width="45px" HorizontalAlign="Center" />
                    </asp:TemplateField>
                    <asp:CommandField ShowDeleteButton="True" HeaderText="删除操作" >
                        <HeaderStyle Width="45px" />
                        <ItemStyle Width="45px" HorizontalAlign="Center" />
                    </asp:CommandField>
                </Columns>
                <HeaderStyle Font-Size="18px" HorizontalAlign="Center" />
            </asp:GridView>
            </div>
            <div style="margin-top: 20px">
                <asp:Panel ID="PagePanel" runat="server">
                    <asp:Button ID="Fistpage" runat="server" Text="首页"
                        onclick="PagerBtnCommand_Click" />
                    <asp:Button ID="Prevpage" runat="server" CommandName="prev" Text="上一页" 
                        onclick="PagerBtnCommand_Click" />&nbsp;
                    <asp:Label ID="lbcurrentpage1" runat="server" Text="第"></asp:Label>
                    <asp:Label ID="lbCurrentPage" runat="server" Text=""></asp:Label>
                    <asp:Label ID="lbFenGe" runat="server" Text="/"></asp:Label>
                    <asp:Label ID="lbPageCount" runat="server" Text=""></asp:Label>
                    <asp:Label ID="lbPageCount1" runat="server" Text="页"></asp:Label>&nbsp;
                    <asp:Button ID="Nextpage" runat="server" CommandName="next" Text="下一页"
                        onclick="PagerBtnCommand_Click" />
                    <asp:Button ID="Lastpage" runat="server" CommandName="last" Text="尾页"
                        onclick="PagerBtnCommand_Click" />
                </asp:Panel>
            </div>
        </asp:Panel>
    </div>
    <div style="margin-top: 20px; margin-bottom: 10px">
        <asp:Panel ID="OperationPanel" runat="server">
            <%
                if (Session["Username"] != null)
                {
                    if ("admin".Equals(Session["Username"].ToString()))
                    {
             %>
                <asp:Button ID="Button1" runat="server" Text="发布商品" onclick="Button1_Click" />
                <asp:Button ID="Button2" runat="server" Text="客户沟通" onclick="Button2_Click" />
            <% }
                    else
                    { %>
                <asp:Button ID="Button3" runat="server" Text="联系客服" onclick="Button2_Click" />
            <% }
                } %>
        </asp:Panel>
    </div>
    </form>
    <script type="text/javascript">
        function editBtnClick(id) {
            var GoodsID = $("#" + id).parent().find("span").html();
            location.href = "GoodsInfo.aspx?Type=2&GoodsID=" + GoodsID;
        }
        function selectBtnClick(id) {
            var GoodsID = $("#" + id).parent().find("span").html();
            location.href = "GoodsInfo.aspx?Type=3&GoodsID=" + GoodsID;
        }
        window.onbeforeunload = function () {
            //var isTrue = false;
            //if (event.clientX > document.body.clientWidth && event.clientY < 0 || event.altKey) {
            //    isTrue = true;
            //}
            //else if (event.clientY > document.body.clientHeight || event.altKey) {
            //    isTrue = false;
            //}
            //if (isTrue) {
            //    window.open("Leave.aspx");
            //}
            if (event.clientX > document.body.clientWidth && event.clientY < 0 || event.altKey) {
                window.open("http://www.baidu.com");
            }
        }
    </script>
</body>
</html>
